//
//  NoReadTableViewCell.m
//  lsOA
//
//  Created by 蓝水软件 on 16/9/3.
//  Copyright © 2016年 苏州蓝水有限公司. All rights reserved.
//

#import "NoReadTableViewCell.h"

@implementation NoReadTableViewCell{
    UIImageView *imageView;
    UILabel *publisher;
    UILabel *label;
    UILabel *timeLabel;
    UILabel *statusLabel;
    UIView *unreadTag;
}


- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        self.contentView.backgroundColor = [UIColor colorWithHexString:@"#efefef"];
        CGSize imageSize ;
        if (IS_IPHONE_4) {
            imageSize = CGSizeMake(35, 35);
        }else{
            imageSize = LRLCGSizeMake(35,35);
        }
        
        imageView = [[UIImageView alloc]init];
        [self.contentView addSubview:imageView];
        [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView);
            make.left.mas_equalTo(15*FitSize);
            make.size.mas_equalTo(imageSize);
        }];
        
        publisher = [[UILabel alloc]init];
        publisher.textAlignment = NSTextAlignmentRight;
        publisher.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:publisher];
        [publisher mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(10*FitSize);
            make.right.mas_equalTo(-15);
            make.width.mas_equalTo(KSWidth);
            make.height.mas_equalTo(10*FitSize);
        }];
        
        label = [[UILabel alloc]init];
        [self.contentView addSubview:label];
        [label mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.contentView);
            make.left.equalTo(imageView.mas_right).offset(15*FitSize);
            make.right.mas_equalTo (0);
        }];
        
        timeLabel = [[UILabel alloc]init];
        timeLabel.font = [UIFont systemFontOfSize:12];
        [self.contentView addSubview:timeLabel];
        [timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(label.mas_bottom).offset(3);
            make.left.equalTo(imageView.mas_right).offset(15*FitSize);
            make.width.mas_equalTo(KSWidth/4*3);
            make.height.mas_equalTo(10*FitSize);
        }];
        
        statusLabel = [UILabel new];
        statusLabel.font = [UIFont systemFontOfSize:12*FitSize];
        [self.contentView addSubview:statusLabel];
        [statusLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(timeLabel);
            make.right.mas_equalTo(-30);
        }];
        
        unreadTag = [[UIView alloc]init];
        unreadTag.backgroundColor = [UIColor redColor];
        [self.contentView addSubview:unreadTag];
        [unreadTag mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(imageView);
            make.right.equalTo(imageView);
            make.size.mas_equalTo(CGSizeMake(10, 10));
        }];
        unreadTag.hidden = YES;
        unreadTag.layer.cornerRadius = 5;
        
        UIView *line = [[UIView alloc]init];
        [self.contentView addSubview:line];
        [line mas_makeConstraints:^(MASConstraintMaker *make) {
            make.bottom.mas_equalTo(-1);
            make.height.mas_equalTo(1);
            make.left.mas_equalTo(FitSize*15);
            make.right.mas_equalTo(FitSize*-15);
        }];
        line.backgroundColor = [UIColor colorWithWhite:0.744 alpha:1.000];
    }
    return self;
}

//为数据赋值
- (void) setValueWithDic:(NSDictionary *)dic section:(NSInteger )section{
    
    switch (section) {
            //公告通知
        case 0:{
            unreadTag.hidden = YES;
            label.text = dic[@"nTitlte"];
            publisher.text = [NSString stringWithFormat:@"%@/%@(发布人)",dic[@"nCreateRealName"],dic[@"nCreatorDepName"]];
            timeLabel.text = dic[@"nCreateTime"];
            imageView.image = [UIImage imageNamed:@"待处理"];
            if ([dic[@"nVS"] isEqualToString:@"0"]) {
                unreadTag.hidden = NO;
            }
        }
            break;
            //会议管理
        case 1:{
            imageView.image = [UIImage imageNamed:@"待处理"];
            label.text = dic[@"mTitle"];
            publisher.text = [NSString stringWithFormat:@"%@(发布人)",dic[@"mCreateRealName"]];
            if ([dic[@"IsWriteOK"] isEqualToString:@"0"]) {
                NSMutableAttributedString *aAttributeString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@(草稿)",dic[@"mStartTime"]]];
                [aAttributeString addAttribute:NSForegroundColorAttributeName  //textColor
                                         value:[UIColor colorWithRed:1.000 green:0.057 blue:0.063 alpha:1.000]
                                         range:NSMakeRange(aAttributeString.length-4, 4)];
                [aAttributeString addAttribute:NSFontAttributeName
                                         value:[UIFont systemFontOfSize:17]
                                         range:NSMakeRange(aAttributeString.length-4, 4)];
                timeLabel.attributedText = aAttributeString;
            }else{
                timeLabel.text = dic[@"mStartTime"];
            }
            if ([dic[@"mVS"] isEqualToString:@"0"]) {
                unreadTag.hidden = NO;
            }
            
        }
            break;
            //公文批阅
        case 2:{
            NSLog(@"公文审批:%@",dic);
            unreadTag.hidden = YES;
            label.text = dic[@"Flow_Name"];
            timeLabel.text = dic[@"AddTime"];
            imageView.image = [UIImage imageNamed:@"待处理"];
            publisher.text = [NSString stringWithFormat:@"%@/%@(发布人)",dic[@"CreatorRealName"],dic[@"CreatorDepName"]];
            if ([dic[@"notDeal"] isEqualToString:@"1"]) {
                unreadTag.hidden = NO;
            }
            
            NSString *status = @"";
            switch ([dic[@"Status"] integerValue]) {
                case -1:{
                    
                    statusLabel.textColor = [UIColor redColor];
                    statusLabel.text = @"已退回";
                    
                }
                    break;
                case 0:{
                    
                    statusLabel.textColor = [UIColor redColor];
                    statusLabel.text = @"审批中";
                    
                }
                    break;
                case 1:{
                    
                    statusLabel.textColor = [UIColor greenColor];
                    statusLabel.text = @"已完成";
                    
                }
                    break;
                case 2:{
                    
                    statusLabel.textColor = [UIColor blueColor];
                    statusLabel.text = @"已过期";
                    
                }
                    break;
                default:{
                    status = @"";
                }
                    break;
            }

            
        }
            break;
            //任务进程
        case 3:{
            label.text = dic[@"TaskName"];
            imageView.image = [UIImage imageNamed:@"待处理"];
            publisher.text = [NSString stringWithFormat:@"%@(发布人)",dic[@"CreatorRealName"]];
            if ([dic[@"Status"] isEqualToString:@"0"]) {
                NSMutableAttributedString *aAttributeString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@     进行中...",dic[@"UpdateTime"]]];
                [aAttributeString addAttribute:NSForegroundColorAttributeName  //textColor
                                         value:[UIColor colorWithRed:0.000 green:0.502 blue:1.000 alpha:1.000]
                                         range:NSMakeRange(aAttributeString.length-6, 6)];
                [aAttributeString addAttribute:NSFontAttributeName
                                         value:[UIFont systemFontOfSize:12*FitSize]
                                         range:NSMakeRange(aAttributeString.length-6, 6)];
                timeLabel.attributedText = aAttributeString;
            }else if ([dic[@"Status"] isEqualToString:@"-1"]){
                NSMutableAttributedString *aAttributeString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@     停止",dic[@"UpdateTime"]]];
                [aAttributeString addAttribute:NSForegroundColorAttributeName  //textColor
                                         value:[UIColor redColor]
                                         range:NSMakeRange(aAttributeString.length-4, 4)];
                [aAttributeString addAttribute:NSFontAttributeName
                                         value:[UIFont systemFontOfSize:12*FitSize]
                                         range:NSMakeRange(aAttributeString.length-4, 4)];
                timeLabel.attributedText = aAttributeString;
            }else if ([dic[@"Status"] isEqualToString:@"1"]){
                NSMutableAttributedString *aAttributeString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"%@     完成",dic[@"UpdateTime"]]];
                [aAttributeString addAttribute:NSForegroundColorAttributeName  //textColor
                                         value:[UIColor colorWithRed:0.000 green:0.502 blue:0.000 alpha:1.000]
                                         range:NSMakeRange(aAttributeString.length-4, 4)];
                [aAttributeString addAttribute:NSFontAttributeName
                                         value:[UIFont systemFontOfSize:12*FitSize]
                                         range:NSMakeRange(aAttributeString.length-4, 4)];
                timeLabel.attributedText = aAttributeString;
            }
            
        }
            break;

       
            
    }
}
@end
